<template>
  <div class="container">
    <h1>API 处理工具</h1>
    <div class="form-group">
      <label for="token">Token:</label>
      <input 
        type="text" 
        id="token" 
        v-model="token"
        placeholder="请输入token"
      >
    </div>
    <div class="form-group">
      <label for="inputString">输入字符串（用逗号分隔）:</label>
      <textarea 
        id="inputString" 
        v-model="inputString"
        placeholder="请输入用逗号分隔的字符串"
      ></textarea>
    </div>
    <button @click="processData">处理数据</button>
    <div>
      <h3>结果:</h3>
      <div id="result" v-html="result"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ApiProcessor',
  data() {
    return {
      token: '',
      inputString: '',
      result: ''
    }
  },
  methods: {
    async processData() {
      if (!this.token || !this.inputString) {
        alert('请填写所有字段');
        return;
      }

      try {
        this.result = '正在处理，请稍候...';
        const response = await fetch('/api/test', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          }
          ,
          body: JSON.stringify({
            token: this.token,
            input_string: this.inputString,
            aa:"jquery-3.2.1.min.js"
          })
        });

        const data = await response.json();
        this.result = JSON.stringify(data, null, 2);
      } catch (error) {
        this.result = '发生错误: ' + error.message;
      }
    }
  }
}
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  background-color: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  max-width: 800px;
  margin: 0 auto;
}

h1 {
  color: #333;
  text-align: center;
  margin-bottom: 20px;
}

textarea {
  width: 100%;
  height: 200px;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  resize: vertical;
}

input[type="text"] {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}

button {
  padding: 12px 24px;
  background-color: #4CAF50;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #45a049;
}

#result {
  white-space: pre-wrap;
  padding: 15px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f9f9f9;
  min-height: 100px;
  font-family: monospace;
  font-size: 14px;
}

.form-group {
  margin-bottom: 15px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  color: #555;
}
</style> 